#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

int n, m;
int head[N];
int ver[N << 1], Next[N << 1], tot;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
int dfn[N], num;
int dep[N], fa[N][20];
void dfs(int u, int fu) {
  dfn[u] = ++num;
  dep[u] = dep[fu] + 1;
  fa[u][0] = fu;
  rep(i, 1, 19) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs(v, u);
  }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  per(i, 19, 0) if (d & (1 << i)) u = fa[u][i];
  if (u == v) return u;
  per(i, 19, 0) if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}

bool cmp(int x, int y) { return dfn[x] < dfn[y]; }
int k, a[N], sz[N];
int st[N], top;
vector<int> g[N];
void build(int root) {
  st[top = 1] = root;
  if (a[1] != root) st[++top] = a[1];
  rep(i, 2, k) {
    int x = lca(st[top], a[i]);
    while (top > 1 && dep[st[top - 1]] >= dep[x])
      g[st[top - 1]].push_back(st[top]), top--;
    if (x != st[top]) g[x].push_back(st[top]), st[top] = x;
    st[++top] = a[i];
  }
  while (top > 1) g[st[top - 1]].push_back(st[top]), top--;
}
ll ans;
int mn, mx;
int mxd[N][2], mnd[N][2];
void dfs(int u) {
  mxd[u][0] = mxd[u][1] = 0;
  mnd[u][0] = mnd[u][1] = 1e6;
  if (sz[u]) mnd[u][1] = 0;
  for (int v : g[u]) {
    dfs(v);
    ans += 1ll * (dep[v] - dep[u]) * sz[v] * (k - sz[v]);
    sz[u] += sz[v];
    sz[v] = 0;
    mxd[u][0] = max(mxd[u][0], mxd[v][1] + dep[v] - dep[u]);
    if (mxd[u][0] > mxd[u][1]) swap(mxd[u][0], mxd[u][1]);
    mnd[u][0] = min(mnd[u][0], mnd[v][1] + dep[v] - dep[u]);
    if (mnd[u][0] < mnd[u][1]) swap(mnd[u][0], mnd[u][1]);
  }
  mx = max(mx, mxd[u][0] + mxd[u][1]);
  // if u is a key vertex, mnd[u][1] === 0
  if (sz[u] > 1) mn = min(mn, mnd[u][0] + mnd[u][1]);
  g[u].clear();
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  // 提取lca信息, dfn信息
  dfs(1, 0);

  cin >> m;
  while (m--) {
    cin >> k;
    rep(i, 1, k) cin >> a[i];
    rep(i, 1, k) sz[a[i]] = 1;  // 关键点
    sort(a + 1, a + k + 1, cmp);
    int root = lca(a[1], a[k]);
    build(root);
    ans = 0, mn = 1e9, mx = 0;
    dfs(root);
    sz[root] = 0;
    cout << ans << ' ' << mn << ' ' << mx << endl;
  }
  return 0;
}